import com.tedu.springdemo.day01.NetConnStaticFactory;
import com.tedu.springdemo.day01.NetConnection;
import com.tedu.springdemo.day01.NetConnectionUnstaticFactory;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class test03 {
    @Test
    public void test01()
    {
//        获取网络连接对象NetConnection对象
        //不用去创建对象，使用方法创建对象并调用相关方法
        //最后 验收成果即可
        NetConnection nc=NetConnStaticFactory.getInstance();
        nc.sendData();
    }

    @Test
    public void test02()
    {
        NetConnectionUnstaticFactory n=new NetConnectionUnstaticFactory();
        NetConnection nc1=n.getInstance();
        nc1.sendData();
    }
    //如何用 spring容器 实现上述设计模式
    @Test
    public void test()
    {
        ApplicationContext ac=new ClassPathXmlApplicationContext("beans5.xml");
        NetConnection nc=(NetConnection)ac.getBean("nc");
        nc.sendData();
        ((ClassPathXmlApplicationContext)ac).close();
    }
    @Test
    public  void test04()
    {
        ApplicationContext ac=new ClassPathXmlApplicationContext("beans6.xml");
        NetConnection nc=(NetConnection) ac.getBean("NCUF");
        nc.sendData();

    }
    @Test
    public void test05()
    {
        ApplicationContext ac=new ClassPathXmlApplicationContext("beans7.xml");
        NetConnection nc=(NetConnection)ac.getBean("sp");
        nc.sendData();
        ((ClassPathXmlApplicationContext)ac).close();
        //单例类   单例实例

    }
}
